package com.fs.video.cotroller;

import com.fs.video.common.utils.SukeJSONResult;
import com.fs.video.pojo.Videos;
import com.fs.video.service.VideosService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/video")
public class VideosController {
    @Autowired
    private VideosService videosService;


    @PostMapping("/updateVideo")
    /**
     * 上传视频
     */
    public SukeJSONResult updateVideo(String userId, MultipartFile video){
        if(userId == null || userId.isEmpty()){
            return SukeJSONResult.errorMsg("用户id不能空");
        }
        String filePath = videosService.upload(userId,video);
        return SukeJSONResult.ok(filePath);
    }

    /**
     * 保存视频信息
     */
    @PostMapping("/saveVideo")
    public SukeJSONResult saveVideo(@RequestBody  Videos videos){
        if(videos == null || videos.getUserId() == null ||  videos.getUserId().isEmpty()){
            return SukeJSONResult.errorMsg("用户id不能空");
        }
        videosService.save(videos);
        return SukeJSONResult.ok("上传成功");
    }

    /**
     * 分页查询
     */
    @RequestMapping("/queryByPage")
    public SukeJSONResult queryByPage(@RequestParam(defaultValue = "1") Integer pageIndex, @RequestParam(defaultValue = "3")  Integer pageSize){
      return SukeJSONResult.ok(videosService.selectByPage(pageIndex,pageSize));
    }

}
